@workover/cli 0.14.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/bin/workover.mjs +117 -0
- package/lib.mjs +42 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -296,6 +296,36 @@ writing, the structure and the pictures alone. Like `reshoot`, it needs `workove
|
|
|
296
296
|
and `--write` needs `--write` too. A project with no linked repository has nothing to check
|
|
297
297
|
against, so the command says so rather than pretending to have checked.
|
|
298
298
|
|
|
299
|
+
### Drafting the WordPress post
|
|
300
|
+
|
|
301
|
+
`workover doc wp-draft` creates the WordPress post a document will publish to, as a draft, and
|
|
302
|
+
links the two. The person who opens the document then publishes it with one click, into the right
|
|
303
|
+
content type, with nothing to fill in. It is for a scheduled writer, such as a weekly changelog,
|
|
304
|
+
that drafts in Workover and leaves publishing to a person.
|
|
305
|
+
|
|
306
|
+
```sh
|
|
307
|
+
workover doc wp-draft 1234 --type changelog
|
|
308
|
+
workover doc wp-draft 1234 --type changelog --slug weekly-update \
|
|
309
|
+
--excerpt "One line for feeds" --taxonomies '{"changelog_product":[50,52]}' --acf '{"summary":"…"}'
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
It always creates a draft; nothing run from the CLI puts a page live. A document that is already
|
|
313
|
+
on WordPress is refused, since a second post would split it in two. It needs
|
|
314
|
+
`workover login --publish`.
|
|
315
|
+
|
|
316
|
+
### Uploading a screenshot
|
|
317
|
+
|
|
318
|
+
`workover doc upload` puts an image into a document's media and prints the markdown that places it,
|
|
319
|
+
for a scheduled job that captures screenshots and then proposes them into a draft.
|
|
320
|
+
|
|
321
|
+
```sh
|
|
322
|
+
workover doc upload 1234 inbox.png --alt "Inbox → Suggestions with a spelling fix open"
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Nothing in the document changes until that markdown is written or proposed. Only PNG, JPEG, GIF and
|
|
326
|
+
WebP files up to 5 MB are sent, never one inside a hidden (dot) directory, and symlinks are judged by
|
|
327
|
+
what they point to.
|
|
328
|
+
|
|
299
329
|
## Coworking with Claude Code
|
|
300
330
|
|
|
301
331
|
Pair it with the [Workover MCP server](https://www.npmjs.com/package/@workover/mcp):
|
package/bin/workover.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
mkdirSync,
|
|
15
15
|
existsSync,
|
|
16
16
|
rmSync,
|
|
17
|
+
realpathSync,
|
|
18
|
+
statSync,
|
|
17
19
|
} from 'fs';
|
|
18
20
|
import { homedir } from 'os';
|
|
19
21
|
import { dirname, join } from 'path';
|
|
@@ -36,6 +38,8 @@ import {
|
|
|
36
38
|
environmentMismatch,
|
|
37
39
|
imagesInHtml,
|
|
38
40
|
signInHelp,
|
|
41
|
+
jsonObjectFlag,
|
|
42
|
+
vetImageUpload,
|
|
39
43
|
} from '../lib.mjs';
|
|
40
44
|
|
|
41
45
|
/*
|
|
@@ -786,6 +790,12 @@ const DOC_USAGE = [
|
|
|
786
790
|
' the linked repository and corrects what it finds wrong;',
|
|
787
791
|
' applied as suggestions, or directly with --write. Needs',
|
|
788
792
|
' `login --draft`',
|
|
793
|
+
' wp-draft <doc> --type <post type> create the WordPress DRAFT of this',
|
|
794
|
+
' [--slug <s>] [--excerpt "<t>"] document, linked to it, on its project\u2019s',
|
|
795
|
+
' [--taxonomies <json>] site. Never live: Publish stays a click',
|
|
796
|
+
' [--acf <json>] [--json] in Workover. Needs `login --publish`',
|
|
797
|
+
' upload <doc> <image> [--alt "<text>"] upload a screenshot into the document’s',
|
|
798
|
+
' [--json] media; prints the markdown to place it',
|
|
789
799
|
' images <doc> [--tab <tabId>] [--json] the images in it: file name, alt',
|
|
790
800
|
' image <doc> <n | --src <url>> set an image’s file name and/or',
|
|
791
801
|
' [--name <file>] [--alt "<text>"] alt text; needs `login --write`',
|
|
@@ -986,6 +996,8 @@ async function docCommand() {
|
|
|
986
996
|
'activity',
|
|
987
997
|
'reshoot',
|
|
988
998
|
'verify',
|
|
999
|
+
'wp-draft',
|
|
1000
|
+
'upload',
|
|
989
1001
|
'images',
|
|
990
1002
|
'image',
|
|
991
1003
|
].includes(sub)
|
|
@@ -1381,6 +1393,111 @@ async function docCommand() {
|
|
|
1381
1393
|
return;
|
|
1382
1394
|
}
|
|
1383
1395
|
|
|
1396
|
+
if (sub === 'wp-draft') {
|
|
1397
|
+
// A scheduled writer (Scout's weekly changelog) drafts a post here and a person publishes it.
|
|
1398
|
+
// That only works if the document is ALREADY linked to a WordPress post of the right type when
|
|
1399
|
+
// the person opens it, so Publish is one click and lands in the right content type. The API's
|
|
1400
|
+
// publish route creates and links that post; this always sends `status: draft`, so nothing an
|
|
1401
|
+
// agent runs from here can put a page live.
|
|
1402
|
+
const usage =
|
|
1403
|
+
'workover doc wp-draft <doc> --type <post type> [--slug <s>] [--excerpt "<text>"] [--taxonomies <json>] [--acf <json>]';
|
|
1404
|
+
const docId = await resolveDocArg(cfg, positionals, usage);
|
|
1405
|
+
const type = typeof flags.type === 'string' ? flags.type.trim() : '';
|
|
1406
|
+
if (!type) {
|
|
1407
|
+
console.log(`\n Usage: ${usage}`);
|
|
1408
|
+
console.log(' --type is the WordPress post type, for example changelog or posts.\n');
|
|
1409
|
+
process.exit(1);
|
|
1410
|
+
}
|
|
1411
|
+
const objectFlag = (name) => {
|
|
1412
|
+
const v = jsonObjectFlag(flags[name]);
|
|
1413
|
+
if (v !== null) return v;
|
|
1414
|
+
console.log(`\n ✗ --${name} must be a JSON object, for example '{"changelog_product":[50]}'.\n`);
|
|
1415
|
+
process.exit(1);
|
|
1416
|
+
};
|
|
1417
|
+
const taxonomies = objectFlag('taxonomies');
|
|
1418
|
+
const acf = objectFlag('acf');
|
|
1419
|
+
|
|
1420
|
+
const doc = await authedCall(cfg, `/project/doc/${docId}`);
|
|
1421
|
+
if (!doc?.id) {
|
|
1422
|
+
console.error(`\n ✗ Document ${docId} not found (or no access).\n`);
|
|
1423
|
+
process.exit(1);
|
|
1424
|
+
}
|
|
1425
|
+
// The LIVE body, as `doc read` uses: the row's `content` is only written on a WordPress import.
|
|
1426
|
+
let live = null;
|
|
1427
|
+
try {
|
|
1428
|
+
live = await authedCall(cfg, `/project/doc/${docId}/content`);
|
|
1429
|
+
} catch {
|
|
1430
|
+
live = null;
|
|
1431
|
+
}
|
|
1432
|
+
const html = live?.html || doc.content || '';
|
|
1433
|
+
if (!html.trim()) {
|
|
1434
|
+
console.error('\n ✗ The document is empty, so there is nothing to draft on WordPress.\n');
|
|
1435
|
+
process.exit(1);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
const result = await authedCall(cfg, `/project/doc/${docId}/wp/publish`, {
|
|
1439
|
+
html,
|
|
1440
|
+
title: doc.title,
|
|
1441
|
+
typePost: type,
|
|
1442
|
+
status: 'draft',
|
|
1443
|
+
...(typeof flags.slug === 'string' ? { slug: flags.slug } : {}),
|
|
1444
|
+
...(typeof flags.excerpt === 'string' ? { excerpt: flags.excerpt } : {}),
|
|
1445
|
+
...(taxonomies ? { taxonomies } : {}),
|
|
1446
|
+
...(acf ? { acf } : {}),
|
|
1447
|
+
});
|
|
1448
|
+
if (asJson) return console.log(JSON.stringify(result, null, 2));
|
|
1449
|
+
const postId = result?.wpPostId ?? result?.id ?? null;
|
|
1450
|
+
console.log(
|
|
1451
|
+
`\n \x1b[32m✓\x1b[0m WordPress draft${postId ? ` #${postId}` : ''} created and linked to document #${docId}.`,
|
|
1452
|
+
);
|
|
1453
|
+
console.log(' It is not live. Publish it from the document in Workover.\n');
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
if (sub === 'upload') {
|
|
1458
|
+
// Puts an image (a screenshot a scheduled job captured) into the document's media and prints the
|
|
1459
|
+
// markdown that places it. Nothing in the document changes until that markdown is written or
|
|
1460
|
+
// proposed, so this is safe to run unattended. Same route and guards as the MCP's upload tool.
|
|
1461
|
+
const usage = 'workover doc upload <doc> <image.png> [--alt "<text>"]';
|
|
1462
|
+
const docId = await resolveDocArg(cfg, positionals.slice(0, 1), usage);
|
|
1463
|
+
const file = positionals[1];
|
|
1464
|
+
if (!file) {
|
|
1465
|
+
console.log(`\n Usage: ${usage}\n`);
|
|
1466
|
+
process.exit(1);
|
|
1467
|
+
}
|
|
1468
|
+
let real;
|
|
1469
|
+
let size;
|
|
1470
|
+
try {
|
|
1471
|
+
real = realpathSync(file);
|
|
1472
|
+
size = statSync(real).size;
|
|
1473
|
+
} catch {
|
|
1474
|
+
console.error(`\n ✗ No file at ${file}.\n`);
|
|
1475
|
+
process.exit(1);
|
|
1476
|
+
}
|
|
1477
|
+
const vetted = vetImageUpload(real, size);
|
|
1478
|
+
if (vetted.error) {
|
|
1479
|
+
console.error(`\n ✗ ${vetted.error}\n`);
|
|
1480
|
+
process.exit(1);
|
|
1481
|
+
}
|
|
1482
|
+
const alt = typeof flags.alt === 'string' ? flags.alt : '';
|
|
1483
|
+
const form = new FormData();
|
|
1484
|
+
form.append('file', new Blob([readFileSync(real)], { type: vetted.mime }), real.split('/').pop());
|
|
1485
|
+
if (alt) form.append('alt', alt);
|
|
1486
|
+
const res = await fetch(`${cfg.api}/project/doc/${docId}/media`, {
|
|
1487
|
+
method: 'POST',
|
|
1488
|
+
headers: { authorization: `Bearer ${cfg.token}` },
|
|
1489
|
+
body: form,
|
|
1490
|
+
});
|
|
1491
|
+
if (!res.ok) {
|
|
1492
|
+
console.error(`\n ✗ Upload failed (${res.status}): ${(await res.text()).slice(0, 200)}\n`);
|
|
1493
|
+
process.exit(1);
|
|
1494
|
+
}
|
|
1495
|
+
const { url } = await res.json();
|
|
1496
|
+
if (asJson) return console.log(JSON.stringify({ url, alt, markdown: `` }, null, 2));
|
|
1497
|
+
console.log(``);
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1384
1501
|
if (sub === 'activity') {
|
|
1385
1502
|
const docId = await resolveDocArg(cfg, positionals, 'workover doc activity <doc>');
|
|
1386
1503
|
const limit = rowId(flags.limit) ?? 20;
|
package/lib.mjs
CHANGED
|
@@ -479,3 +479,45 @@ export const signInHelp = (hint, configFile) =>
|
|
|
479
479
|
...(configFile ? [` The sign-in is saved to ${configFile}.`] : []),
|
|
480
480
|
'',
|
|
481
481
|
].join('\n');
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* A flag that carries a JSON object, such as `--taxonomies '{"changelog_product":[50]}'`.
|
|
485
|
+
*
|
|
486
|
+
* Returns `undefined` when the flag is absent, the object when it parses to one, and `null` when it
|
|
487
|
+
* is present but not a JSON object (an array, a number, or broken JSON), so the caller can say so
|
|
488
|
+
* rather than sending something the API would misread.
|
|
489
|
+
*/
|
|
490
|
+
export const jsonObjectFlag = (value) => {
|
|
491
|
+
if (value == null) return undefined;
|
|
492
|
+
try {
|
|
493
|
+
const v = JSON.parse(String(value));
|
|
494
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : null;
|
|
495
|
+
} catch {
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
/** The image types the API's media upload accepts, and its size cap (apps/api multer config). */
|
|
501
|
+
export const UPLOAD_IMAGE_EXT = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
|
|
502
|
+
export const UPLOAD_IMAGE_MAX_BYTES = 5 * 1024 * 1024;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Whether `workover doc upload` may send a file. Takes the REAL path (symlinks already resolved, so a
|
|
506
|
+
* `shot.png` that points at a key is judged by its target) and its size. Refuses anything inside a dot
|
|
507
|
+
* file or dot directory (~/.ssh, ~/.workover), anything that is not an image type the API takes, and
|
|
508
|
+
* anything over the API's cap, so a scheduled agent cannot be talked into uploading a secret into a
|
|
509
|
+
* document the whole team can open. Returns `{ ext, mime }` or `{ error }`.
|
|
510
|
+
*/
|
|
511
|
+
export const vetImageUpload = (realPath, size) => {
|
|
512
|
+
const parts = String(realPath).split(/[\\/]/).filter(Boolean);
|
|
513
|
+
if (parts.some((part) => part.startsWith('.')))
|
|
514
|
+
return { error: 'Refusing a file inside a hidden (dot) file or directory.' };
|
|
515
|
+
const ext = (parts.at(-1) || '').split('.').pop().toLowerCase();
|
|
516
|
+
if (!UPLOAD_IMAGE_EXT.includes(ext))
|
|
517
|
+
return { error: `Only ${UPLOAD_IMAGE_EXT.join(', ')} images can be uploaded.` };
|
|
518
|
+
if (!(size > 0)) return { error: 'The file is empty.' };
|
|
519
|
+
if (size > UPLOAD_IMAGE_MAX_BYTES) return { error: 'The image is larger than 5 MB.' };
|
|
520
|
+
const mime = ext === 'jpg' || ext === 'jpeg' ? 'image/jpeg' : `image/${ext}`;
|
|
521
|
+
return { ext, mime };
|
|
522
|
+
};
|
|
523
|
+
|